﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;

namespace RssProxyService.Test.Integration
{
    [TestClass]
    public class FlickerRssMapperTests
    {
        [TestMethod]
        public void ValidXmlPassed_XmlContainsImage_ArticleContainsImageItem()
        {
            string xml = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" +
                    "<feed xmlns=\"http://www.w3.org/2005/Atom\" " +
                          "xmlns:dc=\"http://purl.org/dc/elements/1.1/\" " +
                          "xmlns:flickr=\"urn:flickr:user\" " +
                          "xmlns:media=\"http://search.yahoo.com/mrss/\">" +

                      "<title>Uploads from everyone</title>" +
                      "<link rel=\"self\" href=\"http://api.flickr.com/services/feeds/photos_public.gne\" />" +
                      "<link rel=\"alternate\" type=\"text/html\" href=\"http://www.flickr.com/photos/\"/>" +
                      "<id>tag:flickr.com,2005:/photos/public</id>" +
                      "<icon>http://l.yimg.com/g/images/buddyicon.jpg</icon>" +
                      "<subtitle></subtitle>" +
                      "<updated>2012-01-19T15:56:31Z</updated>" +
                      "<generator uri=\"http://www.flickr.com/\">Flickr</generator>" +

                "<entry>" +
                    "<title>IMGP1572</title>" +
                    "<link rel=\"alternate\" type=\"text/html\" href=\"http://www.flickr.com/photos/71193115@N05/6726040569/\"/>" +
                    "<id>tag:flickr.com,2005:/photo/6726040569</id>" +
                    "<published>2012-01-19T15:56:35Z</published>" +
                    "<updated>2012-01-19T15:56:35Z</updated>" +
                    "<dc:date.Taken>2011-08-14T00:00:53-08:00</dc:date.Taken>" +
                    "<content type=\"html\">			&lt;p&gt;&lt;a href=&quot;http://www.flickr.com/people/71193115@N05/&quot;&gt;cropphotography&lt;/a&gt; posted a photo:&lt;/p&gt;" +
	
                "&lt;p&gt;&lt;a href=&quot;http://www.flickr.com/photos/71193115@N05/6726040569/&quot; title=&quot;IMGP1572&quot;&gt;&lt;img src=&quot;http://farm8.staticflickr.com/7149/6726040569_cb774d067b_m.jpg&quot; width=&quot;176&quot; height=&quot;240&quot; alt=&quot;IMGP1572&quot; /&gt;&lt;/a&gt;&lt;/p&gt;" +

                "</content>" +
                    "<author>" +
                      "<name>cropphotography</name>" +
                      "<uri>http://www.flickr.com/people/71193115@N05/</uri>" +
                      "<flickr:nsid>71193115@N05</flickr:nsid>" +
                      "<flickr:buddyicon>http://farm8.staticflickr.com/7024/buddyicons/71193115@N05.jpg?1322851679#71193115@N05</flickr:buddyicon>" +
                    "</author>" +
                    "<link rel=\"enclosure\" type=\"image/jpeg\" href=\"http://farm8.staticflickr.com/7149/6726040569_cb774d067b_b.jpg\" />" +
                    "<category term=\"\" scheme=\"http://www.flickr.com/photos/tags/\" />" +
                "</entry>" +


                "</feed>";

            FlickerRssMapper mapper = new FlickerRssMapper();

            var articles = mapper.GetMappedItems(xml);
            var article = articles.FirstOrDefault();
            var item = article.Items.Where(itemModel => itemModel.Type == "image").FirstOrDefault();

            Assert.IsNotNull(item);
        }
    }
}
